﻿
// CDrawView.h: CDrawView 类的接口
//

#pragma once
#include "CMemoryDC.h"

class CDrawView : public CScrollView
{
	CMemoryDC m_dc;// 内存绘图句柄用于双缓冲

protected: // 仅从序列化创建
	CDrawView() noexcept;
	DECLARE_DYNCREATE(CDrawView)

private:
	int m_index{ID_DRAW_DRAG};
	CArray<SLayer*> m_ls;
	CColorBox& m_colorBox{theApp.m_colorBox};

// 特性
public:
	CDrawDoc* GetDocument() const;
	BOOL CDrawView::CheckLayer(CPoint point)
	{
		auto nCount = m_ls.GetCount();
		int i = -1;
		while (++i < nCount)
		{
			if (m_ls[i]->Check(point))
				return TRUE;
		}
		return FALSE;
	}

// 操作
public:

// 重写
public:
	virtual void OnDraw(CDC* pDC);  // 重写以绘制该视图
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
	virtual void OnInitialUpdate(); // 构造后第一次调用
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);

// 实现
public:
	virtual ~CDrawView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// 生成的消息映射函数
protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnDrawTools(UINT nID);
	afx_msg void OnUpdateDrawTools(CCmdUI* pCmdUI);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
};

#ifndef _DEBUG  // CDrawView.cpp 中的调试版本
inline CDrawDoc* CDrawView::GetDocument() const
   { return reinterpret_cast<CDrawDoc*>(m_pDocument); }
#endif

